package com.crm.handler;

import com.crm.commons.domain.ErrorResponseData;
import com.crm.commons.domain.ResponseData;
import com.crm.commons.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author junxian.dou
 * @Package：com.crm.config
 * @Project：springboot-crm
 * @name：BussinessExceptionHandler
 * @Date：2024/11/25 16:53
 * @Filename：BussinessExceptionHandler
 * @verson 1.0.0
 * @desc
 */
@RestControllerAdvice
@Order(-1)
public class BussinessExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(BussinessExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public ResponseData responseData(Exception e) {

        e.printStackTrace();
        logger.error(e.getMessage());
        return ErrorResponseData.error(e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseData responseData(BusinessException businessException) {
        return  ResponseData.error(businessException);
    }
}
